/*
 *	2012/10/15 13:57	qin
 */

/*
 *	宏实现
 */
#define htons(A)     ((((uint16)(A) & 0xff00) >> 8) | \
						(((uint16)(A) & 0x00ff) << 8))

#define htonl(A)     ((((uint32)(A) & 0xff000000) >> 24) | \
					(((uint32)(A) & 0x00ff0000) >> 8) | \
					(((uint32)(A) & 0x0000ff00) << 8) | \
					(((uint32)(A) & 0x000000ff) << 24))


/*
 *	适合大端向小端转换，也适合从小端到大端转换
 */
unsigned int ToLittleEndian(unsigned int dwBigEndian)
{
    unsigned char * p = (unsigned char*)&dwBigEndian;
    return (unsigned int)(p[0] << 24) + (unsigned int)(p[1] << 16) +
        (unsigned int)(p[2] << 8) + (unsigned int)p[3];
}

int main()
{
	ToLittleEndian(0xABCD1234);
}
